﻿using GEPL.InterfaceLibrary;
using GEPL.StandardModulesLibrary.ViewModels.Turtle;
using GEPL.StandardModulesLibrary.Views.Turtle;
using System;
using System.Runtime.Serialization;

namespace GEPL.StandardModulesLibrary.Elements.Turtle
{
    [Serializable]
    public class TurtleTurnElement : IElement
    {
        private readonly TurtleTurnViewModel viewModel;

        public TurtleTurnElement()
        {
            viewModel = new TurtleTurnViewModel();
        }

        public TurtleTurnElement(SerializationInfo info, StreamingContext context)
        {
            viewModel = new TurtleTurnViewModel()
            {
                Degrees = info.GetInt32(nameof(viewModel.Degrees)),
                Right = info.GetBoolean(nameof(viewModel.Right)),
                Left = info.GetBoolean(nameof(viewModel.Left))
            };
        }

        public ElementType ElementType
        {
            get { return ElementType.NormalStatement; }
        }

        public ProjectType ProjectType
        {
            get { return ProjectType.TurtleGraphics; }
        }

        public string ElementName
        {
            get { return Properties.Resources.Names_Turn; }
        }

        public object Data
        {
            get { return viewModel; }
        }

        public Type UserControlType
        {
            get { return typeof(TurtleTurnView); }
        }

        public string GetScript()
        {
            var command = viewModel.Right ? "TurnRight" : "TurnLeft";
            return String.Format("Turtle.{0}({1})", command, viewModel.Degrees);
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue(nameof(viewModel.Degrees), viewModel.Degrees);
            info.AddValue(nameof(viewModel.Right), viewModel.Right);
            info.AddValue(nameof(viewModel.Left), viewModel.Left);
        }
    }
}